package com.jb.java.metamodel;

import java.util.Iterator;
import java.util.Vector;
import com.jb.web.renderer.RenderKitImpl;

public class Clazz {
    public static Iterator list(ClassLoader CL) throws NoSuchFieldException, 
                                                       IllegalAccessException {
        Class CL_class = CL.getClass();
        while (CL_class != java.lang.ClassLoader.class) {
            CL_class = CL_class.getSuperclass();
        }
        java.lang.reflect.Field ClassLoader_classes_field = 
            CL_class.getDeclaredField("classes");
        ClassLoader_classes_field.setAccessible(true);
        Vector classes = (Vector)ClassLoader_classes_field.get(CL);
        return classes.iterator();
    }
    /**
     * Loads all classes
     */
    public static void loadedClasses() {
        RenderKitImpl.getRenderer(null);
    }
    static int i=0;
    public static void main(String[] args) throws Exception {
        Class.forName(RenderKitImpl.class.getName());
        ClassLoader myCL = Thread.currentThread().getContextClassLoader();
        while (myCL != null) {
            System.out.println("ClassLoader: " + myCL);
            for (Iterator iter = list(myCL); iter.hasNext(); ) {
                
                processClass((Class) iter.next());
            }
            myCL = myCL.getParent();
        }
    }
    public static void processClass(Class clazz) {
        System.out.println((i++) + "\t" + clazz);
    }
}
